
const loadedCache = {}

const loadFont = async (familyName, fontFamilyUrl) => {
    if (loadedCache[familyName]) {
        return
    }
    const { FontFaceObserver } = window
    const style = document.createElement('style');
    style.innerHTML = `
        @font-face {
            font-family: ${familyName};
            src: url("${fontFamilyUrl}");
        }
    `
    document.head.appendChild(style);
    let fontLoader = new FontFaceObserver(familyName)
    loadedCache[familyName] = 1
    return fontLoader.load()
}

export default loadFont

